using System;
using Microsoft.Xna.Framework;

namespace MicroStar
{
    /// <summary>
    /// Emitter which emits particles in a circular ring
    /// </summary>
    public class CircleEmitter : Emitter
    {
        internal override void Emit(double elapsedMilliseconds, Vector2 position)
        {
            int numParticles = RandomEmissionAmount;

            for (int i = 0; i < numParticles && FreeParticles.Count > 0; i++)
            {
                Particle p = FreeParticles.Dequeue();
                float rads = (float)(Random.NextDouble() * MathHelper.TwoPi);
                Vector2 offset = new Vector2((float)Math.Cos(rads) * Radius, (float)Math.Sin(rads) * Radius);
                Vector2 emitPosition = Vector2.Add(position, offset);
                InitializeParticle(ref p, emitPosition, elapsedMilliseconds);
            }
        }

        /// <summary>
        /// Gets or sets the radius of the circle emitter
        /// </summary>
        public float Radius { get; set; }
    }
}
